home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / gdgif.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  7.7 KB  |  267 lines

  1. /* GNUPLOT -- gdgif.trm */
  2. /*
  3.  * Copyright (C) 1995
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *  GD GIF library
  21.  *
  22.  * AUTHORS
  23.  *  Alex Woo based on gnugraph.trm
  24.  
  25.  * send your comments or suggestions to (info-gnuplot@cs.dartmouth.edu).
  26.  * 
  27.  * This version outputs either color or monochrome GIFs.  The default
  28.  * is 640x480 pixels.  This can be changed with the  'set size' command
  29.  * i.e. size values larger than are okay.
  30.  *
  31.  * link with -Lterm/gd -lgd if your directory structure is gnuplot/term/gd
  32.  *
  33.  * gd is not distributed with gnuplot, because of the UNISYS license thing.
  34.  *
  35.  * find out about gd from http://siva.cshl.org/gd/gd.html
  36.  */
  37. #ifndef GOT_DRIVER_H
  38. #include "driver.h"
  39. #endif
  40.  
  41. #ifdef TERM_REGISTER
  42. register_term(gdgif)
  43. #endif
  44.  
  45. #ifdef TERM_PROTO
  46. TERM_PUBLIC void GD_options __P((void));
  47. TERM_PUBLIC void GD_init __P((void));
  48. TERM_PUBLIC void GD_graphics __P((void));
  49. TERM_PUBLIC void GD_text __P((void));
  50. TERM_PUBLIC void GD_linetype __P((int linetype));
  51. TERM_PUBLIC void GD_move __P((unsigned int x, unsigned int y));
  52. TERM_PUBLIC void GD_vector __P((unsigned int x, unsigned int y));
  53. TERM_PUBLIC void GD_put_text __P((unsigned int x, unsigned int y, char str[]));
  54. TERM_PUBLIC int GD_text_angle __P((int ang));
  55. TERM_PUBLIC int GD_justify_text __P((enum JUSTIFY mode));
  56. TERM_PUBLIC void GD_reset __P((void));
  57.  
  58. #define GD_XMAX 640
  59. #define GD_YMAX 480
  60.  
  61. #define GD_XLAST (GD_XMAX - 1)
  62. #define GD_YLAST (GD_YMAX - 1)
  63.  
  64. #define GD_VCHAR    16   /* default */
  65. #define GD_HCHAR    8   /* default */
  66.  
  67. #define GD_VTIC (GD_YMAX/80)
  68. #define GD_HTIC (GD_XMAX/80)
  69. #define GOT_NEXT_PROTO
  70. #endif
  71.  
  72. #ifndef TERM_PROTO_ONLY
  73. #ifdef TERM_BODY
  74.  
  75. #include "./gd.h"
  76. extern gdFontPtr gdFontSmall;  /* 6x12 */
  77. extern gdFontPtr gdFontLarge;  /* 8x16 */
  78. static gdImagePtr im;
  79. static gdFontPtr GD_font;
  80. static int     GD_color, GD_coltable[8],GD_black,GD_white,GD_red,GD_green,GD_blue,GD_violet,GD_brown;
  81. static int     GD_style[8][6];
  82. static int     GD_posx,GD_posy,GD_moved;    /* position pointer */
  83. static int       GD_ang;            /* rotation flag */
  84.  
  85.  
  86. /* These offsets give a 1" offset from the lower left corner.  This
  87.  * gives a greater range of permissible values in GNUPLOT's size
  88.  * command. */
  89.  
  90. static enum JUSTIFY GD_justify=LEFT;
  91.  
  92. TERM_PUBLIC void GD_options()
  93. {
  94.     if(!END_OF_COMMAND) {
  95.       if(almost_equals(c_token,"d$efault")) {
  96.         GD_font=gdFontLarge;
  97.         term->v_char = (unsigned int)(16);
  98.         term->h_char = (unsigned int)(8);
  99.         c_token++;
  100.       }
  101.     }
  102.  
  103. }
  104.  
  105. TERM_PUBLIC void GD_init()
  106. {
  107.     im = gdImageCreate(GD_XMAX,GD_YMAX);
  108.     GD_white = GD_coltable[0]  = gdImageColorAllocate(im,255,255,255); /* white background */
  109.     GD_black = GD_coltable[1]  = gdImageColorAllocate(im,  0,  0,  0); /* black */
  110.     GD_red   = GD_coltable[2]  = gdImageColorAllocate(im,255,  0,  0); /* red   */
  111.     GD_green = GD_coltable[6]  = gdImageColorAllocate(im,  0,255,  0); /* green */
  112.     GD_blue  = GD_coltable[3]  = gdImageColorAllocate(im,  0,  0,255); /* blue  */
  113.     GD_violet= GD_coltable[4]  = gdImageColorAllocate(im,255,  0,255); /* violet  */
  114.     GD_brown = GD_coltable[5]  = gdImageColorAllocate(im,  0,255,255); /* brown  */
  115.     GD_coltable[7]  = gdImageColorAllocate(im,255,255,  0); /* yellow  */
  116.      /* Line Styles */
  117.     GD_style[0][0] = GD_black; GD_style[0][1] = GD_black;
  118.     GD_style[0][2] = GD_black; GD_style[0][3] = GD_black;
  119.     GD_style[0][4] = GD_black; GD_style[0][5] = GD_black;  /* solid black */
  120.     GD_style[1][0] = GD_black; GD_style[1][2] = GD_black; 
  121.     GD_style[1][2] = GD_black; GD_style[1][3] = GD_black; 
  122.     GD_style[1][4] = GD_black; GD_style[1][5] = gdTransparent; /*longdashed */
  123.     GD_style[2][0] = GD_black; GD_style[2][1] = GD_black;
  124.     GD_style[2][2] = GD_black; GD_style[2][3] = GD_black;
  125.     GD_style[2][4] = GD_black; GD_style[2][5] = GD_black;  /* solid black */
  126.     GD_style[3][0] = GD_black; GD_style[3][1] = gdTransparent; 
  127.     GD_style[3][2] = GD_black; GD_style[3][3] = gdTransparent; 
  128.     GD_style[3][4] = GD_black; GD_style[3][5] = gdTransparent;/* dotted */
  129.     GD_style[4][0] = GD_red; GD_style[4][1] = GD_red; 
  130.     GD_style[4][2] = GD_red; GD_style[4][3] = gdTransparent; 
  131.     GD_style[4][0] = gdTransparent; GD_style[4][5] = gdTransparent; /* shortdash */
  132.     GD_style[5][0] =  GD_blue; GD_style[5][1] = gdTransparent; 
  133.     GD_style[5][2] =  GD_blue; GD_style[5][3] = GD_blue; 
  134.     GD_style[5][4] =  GD_blue; GD_style[5][5] = gdTransparent; /* dotdash */
  135.     GD_style[6][0] =GD_violet; GD_style[6][1] = GD_violet; 
  136.     GD_style[6][2] =GD_violet; GD_style[6][3] = GD_violet; 
  137.     GD_style[6][4] = gdTransparent; GD_style[6][5] = gdTransparent; /* mediandash */
  138.     GD_style[7][0] = GD_green; GD_style[7][1] = GD_green; 
  139.     GD_style[7][2] = GD_green; GD_style[7][3] = gdTransparent; 
  140.     GD_style[7][4] = gdTransparent; GD_style[7][5] = gdTransparent; /* halfdash */
  141.     
  142.     gdImageSetStyle(im,GD_style[0],6);
  143.     GD_font        = gdFontLarge;
  144.     GD_color       = GD_black;
  145. }
  146.  
  147.  
  148. TERM_PUBLIC void GD_graphics()
  149. {
  150.  
  151. }
  152.  
  153.  
  154. TERM_PUBLIC void GD_text()
  155. {
  156.         /* turn on interlace */
  157.     gdImageInterlace(im,1);
  158.             /* Output the image to the disk file. */
  159.     gdImageGif(im, outfile);    
  160.         /* Flush here so that output will be complete. */    
  161.     fflush(outfile);
  162. }
  163.  
  164.  
  165. TERM_PUBLIC void GD_linetype(linetype)
  166. int linetype;
  167. {
  168. static char *lt[2+5] = {"solid", "longdashed", "solid", "dotted","shortdashed",
  169.     "dotdashed", "longdashed"};
  170.     
  171.     if (linetype >= 5)
  172.         linetype %= 5;
  173.     gdImageSetStyle(im,GD_style[linetype+2],6);
  174.     GD_color    = GD_coltable[linetype+1];
  175. }
  176.  
  177.  
  178. TERM_PUBLIC void GD_move(x,y)
  179. unsigned int x,y;
  180. {
  181.     GD_posx = x; GD_posy = y;
  182.     GD_moved = TRUE;
  183. }
  184.  
  185.  
  186. TERM_PUBLIC void GD_vector(ux,uy)
  187. unsigned int ux,uy;
  188. {
  189.     gdImageLine(im,GD_posx,GD_YMAX-GD_posy,ux,GD_YMAX-uy,gdStyled);
  190.     GD_move(ux,uy);
  191. }
  192.  
  193.  
  194. TERM_PUBLIC void GD_put_text(x,y,str)
  195. unsigned int x,y;
  196. char str[];
  197. {
  198.     
  199.     GD_move(x,y); /* Don't adjust x and y! It's done in GD_move. */
  200.     if (GD_ang == 1) {
  201.         gdImageStringUp(im,GD_font,x,GD_YMAX-y,str,GD_color);
  202.     }else gdImageString(im,GD_font,x,GD_YMAX-y,str,GD_color);
  203.  
  204. }
  205.  
  206. TERM_PUBLIC int GD_text_angle(ang)
  207. int ang;
  208. {
  209.     if(ang==1){
  210.          GD_ang=1;
  211.     }else GD_ang=0;
  212.     return TRUE;
  213. }
  214.  
  215. TERM_PUBLIC int GD_justify_text(mode)
  216. enum JUSTIFY mode;
  217. {    /* text is always left and bottom justified */
  218.     GD_justify=mode;
  219.     return FALSE;
  220. }
  221.  
  222. TERM_PUBLIC void GD_reset()
  223. {
  224.  
  225. }
  226.  
  227. #endif /* TERM_BODY*/
  228.  
  229. #ifdef TERM_TABLE
  230.  
  231. TERM_TABLE_START(gdgif_driver)
  232.     "gif", "GIF format format [\042fontname]",
  233.        GD_XMAX, GD_YMAX, GD_VCHAR, GD_HCHAR,
  234.        GD_VTIC, GD_HTIC, GD_options, GD_init, GD_reset,
  235.        GD_text, null_scale, GD_graphics, GD_move, GD_vector,
  236.        GD_linetype, GD_put_text, GD_text_angle,
  237.        GD_justify_text, do_point, do_arrow
  238. TERM_TABLE_END(gdgif_driver)
  239.  
  240. #undef LAST_TERM
  241. #define LAST_TERM gdgif_driver
  242.  
  243. #endif /* TERM_TABLE */
  244. #endif /* TERM_PROTO_ONLY */
  245.  
  246. /*
  247.  * NAME: gif
  248.  *
  249.  * OPTIONS: claims to have font as option, but if I read the code
  250.  *        correctly it only supports the setting `default', which
  251.  *        means 8x16 Font.
  252.  *
  253.  * SUPPORTS: GIF format 
  254.  *
  255.  * Further Info: From top of file:
  256.  *
  257.  * This version outputs either color or monochrome GIFs.  The default
  258.  * is 640x480 pixels.  This can be changed with the  'set size' command
  259.  * i.e. size values larger than are okay.
  260.  *
  261.  * link with -Lterm/gd -lgd if your directory structure is gnuplot/term/gd
  262.  *
  263.  * gd is not distributed with gnuplot, because of the UNISYS license thing.
  264.  *
  265.  * find out about gd from http://siva.cshl.org/gd/gd.html
  266.  *
  267.  */